<?php

namespace App\Admin\Controllers;

use App\Admin\Repositories\UserDepositMethod;
use Dcat\Admin\Form;
use Dcat\Admin\Grid;
use Dcat\Admin\Show;
use Dcat\Admin\Http\Controllers\AdminController;

class UserDepositMethodController extends AdminController
{
    /**
     * Make a grid builder.
     *
     * @return Grid
     */
    protected function grid()
    {
        return Grid::make(new UserDepositMethod(), function (Grid $grid) {
            $grid->column('id')->sortable();
            $grid->column('name');
            $grid->column('type')->using(tt_deposit_method('', true));
            $grid->column('params');
            $grid->column('status')->switch();
            $grid->column('created_at');
            $grid->column('updated_at')->sortable();

            $grid->filter(function (Grid\Filter $filter) {
                $filter->equal('id');

            });
        });
    }

    /**
     * Make a show builder.
     *
     * @param mixed $id
     *
     * @return Show
     */
    protected function detail($id)
    {
        return Show::make($id, new UserDepositMethod(), function (Show $show) {
            $show->field('id');
            $show->field('name');
            $show->field('type');
            $show->field('params');
            $show->field('status');
            $show->field('created_at');
            $show->field('updated_at');
        });
    }

    /**
     * Make a form builder.
     *
     * @return Form
     */
    protected function form()
    {
        return Form::make(new UserDepositMethod(), function (Form $form) {
            $form->display('id');
            $form->text('name');
            $form->select('type')->options(tt_deposit_method('', true));
//            $form->textarea('params');

            $form->embeds('params', function (Form\EmbeddedForm $form) {
                $form->switch("jump", __("是否外跳支付跳转"))->help("信用卡支付平台等需要启用此选项");
                $form->text("jump_product", __("三方产品码，如站内支付不需要填写"));
                $form->text("jump_currency", __("三方跳转币，如站内支付不需要填写"))->help("法币单位");

                $form->text('unit_symbol', __("汇率币"))
                    ->value(ASSET_SYMBOL_DEFAULT)
                    ->required()->help("默认USD，有填写则自动按行情转换显示充值数量");
                $form->list('amount_quick', __("快速充值金额"))->required();
                $form->text('amount_min', __("最小充值金额"))->required();

                $form->text('account', __("账户(号)"))->help("非站外支付方式必填");
                $form->text('name', __("名称"))->help("名称标记");
            })->saving(function ($v) {
                // 转化为json格式存储
                return json_encode($v);
            });

            $form->switch('status');

            $form->display('created_at');
            $form->display('updated_at');
        });
    }
}
